<%@ Page Language="C#" ValidateRequest="false" MasterPageFile="~/SMS.master" AutoEventWireup="true" CodeFile="AddEditProduct.aspx.cs" Inherits="TH.SMS.UI.Admin.AddEditProduct" Title="Safety Manamement System - Add/Edit Product" %>
<%@ Register Src="../Controls/FileUploader.ascx" TagName="FileUploader" TagPrefix="mb" %>
<%@ Register Src="../Controls/RatingDisplay.ascx" TagName="RatingDisplay" TagPrefix="mb" %>
<%@ Register Assembly="FredCK.FCKeditorV2" Namespace="FredCK.FCKeditorV2" TagPrefix="FCKeditorV2" %>

<asp:Content ID="MainContent" ContentPlaceHolderID="MainContent" Runat="Server">
   <div class="sectiontitle">
      <asp:Literal runat="server" ID="lblNewProduct" Text="Insert New Product" />
      <asp:Literal runat="server" ID="lblEditProduct" Text="Edit Product" Visible="false" />
   </div>
   <p></p>
   <asp:DetailsView ID="dvwProduct" runat="server" AutoGenerateDeleteButton="True" AutoGenerateEditButton="True"
      AutoGenerateInsertButton="True" AutoGenerateRows="False" DataKeyNames="ID" DataSourceID="objCurrProduct"
      DefaultMode="Insert" HeaderText="Product Details" OnItemCreated="dvwProduct_ItemCreated" OnDataBound="dvwProduct_DataBound" OnModeChanged="dvwProduct_ModeChanged">
      <FieldHeaderStyle Width="108px" />
      <Fields>
         <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
            SortExpression="ID" />
         <asp:BoundField DataField="AddedDate" HeaderText="Added Date" InsertVisible="False"
            ReadOnly="True" SortExpression="AddedDate" HtmlEncode="false" DataFormatString="{0:f}" />
         <asp:BoundField DataField="AddedBy" HeaderText="Added By" InsertVisible="False" ReadOnly="True"
            SortExpression="AddedBy" />         
         <asp:BoundField DataField="Votes" HeaderText="Votes" InsertVisible="False" ReadOnly="True"
            SortExpression="Votes" />
         <asp:BoundField DataField="AverageRating" HeaderText="Rating" InsertVisible="False"
            HtmlEncode="false" DataFormatString="{0:N2}" ReadOnly="True" SortExpression="AverageRating" />
         <asp:TemplateField HeaderText="Department" SortExpression="DepartmentID">
            <ItemTemplate>
               <asp:Label ID="lblDepartment" runat="server" Text='<%# Eval("DepartmentTitle") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
               <asp:DropDownList ID="ddlDepartments" runat="server" DataSourceID="objAllDepartments"
                  DataTextField="Title" DataValueField="ID" SelectedValue='<%# Bind("DepartmentID") %>' Width="100%" />
               <asp:ObjectDataSource ID="objAllDepartments" runat="server" SelectMethod="GetDepartments"
                  TypeName="TH.SMS.BLL.Store.Department"></asp:ObjectDataSource> 
            </EditItemTemplate>
         </asp:TemplateField>
         <asp:TemplateField HeaderText="Title" SortExpression="Title">
            <ItemTemplate>
               <asp:Label ID="lblTitle" runat="server" Text='<%# Eval("Title") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
               <asp:TextBox ID="txtTitle" runat="server" Text='<%# Bind("Title") %>' Width="100%" MaxLength="256"></asp:TextBox>
               <asp:RequiredFieldValidator ID="valRequireTitle" runat="server" ControlToValidate="txtTitle" SetFocusOnError="true"
                  Text="The Title field is required." ToolTip="The Title field is required." Display="Dynamic"></asp:RequiredFieldValidator>
            </EditItemTemplate>
         </asp:TemplateField>         
         <asp:TemplateField HeaderText="Description" SortExpression="Description">
            <ItemTemplate>
               <asp:Label ID="lblDescription" runat="server" Text='<%# Eval("Description") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
               <fckeditorv2:fckeditor id="txtDescription" runat="server" Value='<%# Bind("Description") %>'
                  ToolbarSet="SMS" Height="400px" Width="100%" />
            </EditItemTemplate>
         </asp:TemplateField>
         <asp:TemplateField HeaderText="SKU" SortExpression="SKU">
            <ItemTemplate>
               <asp:Label ID="lblSKU" runat="server" Text='<%# Eval("SKU") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
               <asp:TextBox ID="txtSKU" runat="server" Text='<%# Bind("SKU") %>' Width="100%" MaxLength="256"></asp:TextBox>
               <asp:RequiredFieldValidator ID="valRequireSKU" runat="server" ControlToValidate="txtSKU" SetFocusOnError="true"
                  Text="The SKU field is required." ToolTip="The SKU field is required." Display="Dynamic"></asp:RequiredFieldValidator>
            </EditItemTemplate>
         </asp:TemplateField>
         <asp:TemplateField HeaderText="Unit Price" SortExpression="UnitPrice">
            <ItemTemplate>
               <asp:Label ID="lblUnitPrice" runat="server" Text='<%# Eval("UnitPrice", "{0:N2}") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
               <asp:TextBox ID="txtUnitPrice" runat="server" Text='<%# Bind("UnitPrice", "{0:N2}") %>' Width="100%" MaxLength="256"></asp:TextBox>
               <asp:RequiredFieldValidator ID="valRequireUnitPrice" runat="server" ControlToValidate="txtUnitPrice" SetFocusOnError="true"
                  Text="The Unit Price field is required." ToolTip="The Unit Price field is required." Display="Dynamic"></asp:RequiredFieldValidator>
               <asp:CompareValidator ID="valUnitPriceType" runat="server" Operator="DataTypeCheck" Type="Currency"
                  ControlToValidate="txtUnitPrice" Text="The Unit Price must be a double."
                  ToolTip="The Unit Price must be a double." Display="dynamic" />
            </EditItemTemplate>
         </asp:TemplateField>
         <asp:TemplateField HeaderText="Discount %" SortExpression="DiscountPercentage">
            <ItemTemplate>
               <asp:Label ID="lblDiscountPercentage" runat="server" Text='<%# Eval("DiscountPercentage") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
               <asp:TextBox ID="txtDiscountPercentage" runat="server" Text='<%# Bind("DiscountPercentage") %>' Width="100%" MaxLength="256"></asp:TextBox>
               <asp:RequiredFieldValidator ID="valRequireDiscountPercentage" runat="server" ControlToValidate="txtDiscountPercentage" SetFocusOnError="true"
                  Text="The Discount Percentage field is required." ToolTip="The Discount Percentage field is required." Display="Dynamic"></asp:RequiredFieldValidator>
               <asp:CompareValidator ID="valDiscountPercentageType" runat="server" Operator="DataTypeCheck" Type="Integer"
                  ControlToValidate="txtDiscountPercentage" Text="The Discount Percentage must be an integer."
                  ToolTip="The Discount Percentage must be an integer." Display="dynamic" />
            </EditItemTemplate>
         </asp:TemplateField>
         <asp:TemplateField HeaderText="Units in Stock" SortExpression="UnitsInStock">
            <ItemTemplate>
               <asp:Label ID="lblUnitsInStock" runat="server" Text='<%# Eval("UnitsInStock") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
               <asp:TextBox ID="txtUnitsInStock" runat="server" Text='<%# Bind("UnitsInStock") %>' Width="100%" MaxLength="256"></asp:TextBox>
               <asp:RequiredFieldValidator ID="valRequireUnitsInStock" runat="server" ControlToValidate="txtUnitsInStock" SetFocusOnError="true"
                  Text="The Discount Units In Stock field is required." ToolTip="The Units In Stock field is required." Display="Dynamic"></asp:RequiredFieldValidator>
               <asp:CompareValidator ID="valUnitsInStockType" runat="server" Operator="DataTypeCheck" Type="Integer"
                  ControlToValidate="txtUnitsInStock" Text="The Units In Stock must be an integer."
                  ToolTip="The Units In Stock must be an integer." Display="dynamic" />
            </EditItemTemplate>
         </asp:TemplateField>
         <asp:TemplateField HeaderText="Small Image Url" SortExpression="SmallImageUrl">
            <ItemTemplate>
               <asp:Label ID="lblSmallImageUrl" runat="server" Text='<%# Eval("SmallImageUrl") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
               <asp:TextBox ID="txtSmallImageUrl" runat="server" Text='<%# Bind("SmallImageUrl") %>' Width="100%" MaxLength="256"></asp:TextBox>
            </EditItemTemplate>
         </asp:TemplateField>
         <asp:TemplateField HeaderText="Full Image Url" SortExpression="FullImageUrl">
            <ItemTemplate>
               <asp:Label ID="lblFullImageUrl" runat="server" Text='<%# Eval("FullImageUrl") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
               <asp:TextBox ID="txtFullImageUrl" runat="server" Text='<%# Bind("FullImageUrl") %>' Width="100%" MaxLength="256"></asp:TextBox>
            </EditItemTemplate>
         </asp:TemplateField>
      </Fields>
   </asp:DetailsView>
   <asp:ObjectDataSource ID="objCurrProduct" runat="server" DeleteMethod="DeleteProduct"
      InsertMethod="InsertProduct" SelectMethod="GetProductByID" TypeName="TH.SMS.BLL.Store.Product"
      UpdateMethod="UpdateProduct">
      <DeleteParameters>
         <asp:Parameter Name="id" Type="Int32" />
      </DeleteParameters>
      <UpdateParameters>
         <asp:Parameter Name="id" Type="Int32" />
         <asp:Parameter Name="departmentID" Type="Int32" />
         <asp:Parameter Name="title" Type="String" ConvertEmptyStringToNull="false" />
         <asp:Parameter Name="description" Type="String" ConvertEmptyStringToNull="false" />
         <asp:Parameter Name="sku" Type="String" ConvertEmptyStringToNull="false" />
         <asp:Parameter Name="unitPrice" Type="Decimal" />
         <asp:Parameter Name="discountPercentage" Type="Int32" />
         <asp:Parameter Name="unitsInStock" Type="Int32" />
         <asp:Parameter Name="smallImageUrl" Type="String" ConvertEmptyStringToNull="false" />
         <asp:Parameter Name="fullImageUrl" Type="String" ConvertEmptyStringToNull="false" />
      </UpdateParameters>
      <SelectParameters>
         <asp:QueryStringParameter Name="productID" QueryStringField="ID" Type="Int32" />
      </SelectParameters>
      <InsertParameters>
         <asp:Parameter Name="departmentID" Type="Int32" />
         <asp:Parameter Name="title" Type="String" ConvertEmptyStringToNull="false" />
         <asp:Parameter Name="description" Type="String" ConvertEmptyStringToNull="false" />
         <asp:Parameter Name="sku" Type="String" ConvertEmptyStringToNull="false" />
         <asp:Parameter Name="unitPrice" Type="Decimal" />
         <asp:Parameter Name="discountPercentage" Type="Int32" />
         <asp:Parameter Name="unitsInStock" Type="Int32" />
         <asp:Parameter Name="smallImageUrl" Type="String" ConvertEmptyStringToNull="false" />
         <asp:Parameter Name="fullImageUrl" Type="String" ConvertEmptyStringToNull="false" />
      </InsertParameters>
   </asp:ObjectDataSource>   
   <p></p>
   <mb:FileUploader id="FileUploader1" runat="server">
   </mb:FileUploader>        
</asp:Content>

